package com.sjms._01_创建_单例;

class X {
    private static volatile X x;

    private X() {
    }

    public static X getInstance() {
        //一重检查
        if (x == null) {

            //加锁
            synchronized (X.class) {

                //二重检查
                if (x == null) {
                    x = new X();
                }

            }
        }

        return x;
    }
}

//双重检查锁
public class Test2 {
    public static void main(String[] args) {
        System.out.println(X.getInstance());
    }
}
